from rest_framework.serializers import ModelSerializer
from rest_framework import serializers
from movie.models import Account, Douban_Movie, Comment, Reply, Behavior


class LoginSerializer(ModelSerializer):
    created_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M:%S')

    class Meta:
        model = Account
        fields = '__all__'


class MovieSerializer(ModelSerializer):
    class Meta:
        model = Douban_Movie
        fields = '__all__'


class AccountSerializer(ModelSerializer):
    class Meta:
        model = Account
        fields = ['username', 'nick_name']


# 二级评论
class ReplySerializer(ModelSerializer):
    user = AccountSerializer(source='reply_author', read_only=True)
    parent = AccountSerializer(source='parent_author', read_only=True)
    reply_created_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M')

    class Meta:
        model = Reply
        fields = '__all__'


# 一级评论
class CommentSerializer(ModelSerializer):
    user = AccountSerializer(source='author', read_only=True)
    replies = ReplySerializer(source='replyTocomment', many=True, read_only=True)
    created_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M')

    class Meta:
        model = Comment
        fields = '__all__'


class BehaviorSerializer(ModelSerializer):
    user = AccountSerializer(read_only=True)
    movie = MovieSerializer(read_only=True)

    class Meta:
        model = Behavior
        fields = '__all__'
